<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var z=/^(\d+,)*\d+$/;
        function f() {
            var value = document.getElementById("zfc").value;
            var num=0;
            if (z.test(value)){
                var strings = value.split(",");
                for (var i=0;i<strings.length;i++){
                     num +=Number(strings[i]);
                }
                alert(value+"的和是:"+num);
            }else {
                alert("输入错误,请重新输入! ! !");
            }
        }
    </script>
</head>
<body>
字符串(1,2,3):
<input id="zfc" type="text"/>
<input type="button" value="求和" onclick="f()"/>
</body>
</html>